import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:totaldemo/getx/controller.dart';
// import 'package:totaldemo/getx/controller.dart';

class StateGetxPage extends StatelessWidget {
  StateGetxPage({Key key}) : super(key: key);
  final controller = CountController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('getx'),
      ),
      body: Center(
        child: Column(
          children: [
            GetX<CountController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('Getx -1 ');
                return Text('value 1-> ${_.count1}');
              },
            ),
            GetX<CountController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('Getx - 2');
                return Text('value 2 -> ${_.count1}');
              },
            ),
            Divider(),
            GetX<CountController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('getx -3');
                return Column(
                  children: [
                    Text('value 3 -> ${_.count1}'),
                    ElevatedButton(
                        onPressed: () {
                          _.add1();
                        },
                        child: Text('count1'))
                  ],
                );
              },
            ),
            //count
            GetX<CountController>(
              init: controller,
              initState: (_) {},
              builder: (_) {
                print('getx - > 4');
                return Text('value4 - > ${_.count2}');
              },
            ),
            Divider(),
            //按钮
            ElevatedButton(
                onPressed: () {
                  controller.add1();
                },
                child: Text('count1')),
            ElevatedButton(
                onPressed: () {
                  controller.add2();
                },
                child: Text('count2'))
          ],
        ),
      ),
    );
  }
}
